<template>
  <div id="licaiDetail">
    <div class="homeTitle">理财交易申请</div>
    
    <div class="tableBox">
      <div>
        <div class="tableTitle">申请人信息： </div>
      <el-form class="formlist" :model="formData1"  :inline="true" :rules="rules">
                    <el-form-item v-for="item in formList1" :key="item.label" :label="item.label" :prop="item.prop">
                    {{formData1[item.prop]}}
                    </el-form-item>
           </el-form>
      </div>
       <div >
      <div class="tableTitle">理财产品信息： </div>
      <el-form class="formlist" :model="formData3"  :inline="true" :rules="rules">
                    <el-form-item v-for="item in formList3" :key="item.label" :label="item.label" :prop="item.prop">
                      <template v-if="item.qujian">
                        {{formData3[item.start]}}~{{formData3[item.end]}}
                      </template>
                      <template v-else>
                        {{(formData3[item.prop] != null && formData3[item.prop] != '') ? formData3[item.prop] : '暂无数据'}}
                      </template>
                       
                    </el-form-item>
           </el-form>
      </div>
      <div class="tableBox">
        <div class="tableTitle">交易详情</div>
         <el-form :model="formData" disabled = 'disabled'  class="formlist" :inline="true" :rules="rules">
                    <el-form-item v-for="item in formList" :key="item.label" :label="item.label" :prop="item.prop">
                    <el-input placeholder="请输入" :disabled="item.disabled" v-if="item.input" class="inputt" v-model= 'formData[item.prop]'></el-input>
                      <template v-else-if="item.btn">
                        <el-button type="text" @click="clickBtn" >{{item.value}}</el-button>
                    </template>
                    <el-select  placeholder="请选择" style="width:100%" v-else-if="item.select" v-model="formData[item.prop]" >
                        <el-option  v-for="option in item.options" :key = "option.label" :label="option.label" :value="option.value"></el-option>
                    </el-select>
                    <el-date-picker  v-else-if="item.date"
                        style="width:100%"
                        v-model="formData[item.prop]"
                        type="date"
                        placeholder="选择日期">
                    </el-date-picker>
                    <div v-else>{{formData[item.prop]}}12</div>
                </el-form-item>
                
            </el-form>
      </div>
            <div v-show="selectedData.length > 0">
        <div class="tableTitle" >赎回明细：</div>
        <el-table :data="selectedData" border style="width: 100%">
          
          <el-table-column prop="code" label="产品代码"  align="center"></el-table-column>
          <el-table-column prop="transactionNumber" label="成交编号" align="center"></el-table-column>
          <el-table-column prop="annualized" label="年化收益率"  align="center"></el-table-column>
          <el-table-column prop="dueDate" label="	结息日"  align="center"></el-table-column>
          <el-table-column prop="initialAmount" label="初始金额" align="center"></el-table-column>
          <el-table-column prop="name" label="产品名称" align="center"></el-table-column>
          <el-table-column prop="term" label="产品期限" align="center"></el-table-column>
          <el-table-column prop="type" label="产品类型" align="center"></el-table-column>
          <el-table-column prop="interestDate" label="起息日" align="center"></el-table-column>
          <el-table-column prop="money" label="赎回金额(元)" align="center"></el-table-column>
        
        </el-table>
      </div>
      <div id="fujian2" v-show="fileList.length > 0" style="width:98%">
          <div class="tableTitle">附件</div>
            <table>
          <tr style="height:50px;background:rgba(53,58,58,0.8)">
            <!-- <td>附件描述</td> -->
            <td>附件名称</td>
            <td>操作</td>
          </tr>
          
          <tr v-for="(file, index) in fileList" :key="index">
            <!-- <td>{{file.info}}</td> -->
            <td>{{file.name}}</td>
            <td>
              <a :href='aurl+ file.filename + "&name=" + file.name' style="font-size:14px;color: #409EFF"  :download="file.name">下载</a>
            </td>
          </tr>
         
        </table>
      </div>
    
         <div style="width:98%">
        <div class="tableTitle">审核记录</div>
        <el-table ref="singleTable" :data="recordShen" border   
              style="width: 100%"
              >
           
            <el-table-column prop="userRole" label="审核角色" align="center"></el-table-column>
            <el-table-column prop="userName" label="用户名称" align="center"></el-table-column>
            
            <el-table-column prop="content" label="审核意见" align="center"></el-table-column>
            <el-table-column prop="createTime" label="审核时间" align="center"></el-table-column>
      
          </el-table>
       </div>
      <div v-show="isUpload" id="shengl" style="width:98%">
        <div class="tableTitle" >省联社授权节点</div>
             <table>
           <tr style="height:50px;background:rgba(53,58,58,0.8)">
            <!-- <td style="width:33%"><span style="color:red">*</span>文件描述</td> -->
            <td>文件名称</td>
            <td>操作</td>
          </tr>
          
          <tr v-for="(file, index) in fileList2" :key="index">
            <!-- <td>{{file.info}}</td> -->
            <td>{{file.name}}</td>
            <td>  
                   <el-button v-if="canUpload" type="text" @click="delFile(index)">删除</el-button>
                    <a v-else :href='aurl+ file.filename  + "&name=" + file.name' style="font-size:14px;color: #409EFF"  :download="file.name">下载</a>
              </td> 
          </tr>
          <tr v-show="canUpload">
            <!-- <td>
              <el-input placeholder="请输入文件描述" v-model="filename"></el-input>
            </td> -->
            <td>
                 <el-upload
                  class="upload-demo"
                  :action="fileupload"
                  :on-preview="handlePreview"
               
                  :on-remove="handleRemove"
        
                  :on-success="uploadSuccess"
                  multiple
                  :limit="3"
                  :on-exceed="handleExceed"
                  :file-list="fileList2">
                  <el-button size="small"  type="text">上传附件</el-button>
                </el-upload>
            </td>
            <td>
              <!-- <el-button @click="addfile" type="text">添加</el-button> -->
            </td>
          </tr>
             </table>
       
      </div>
        <div class="riskTip" style="width:98%">
        <div class="fxtq tableTitle">申请事由：</div>
        <div class="fxcon">
          <p>{{formData.reason}}</p>
        </div>
      </div>
      <div class="riskTip" style="width:98%" v-show="tishiMessage != ''">
        <div class="fxtq tableTitle">风险提醒：</div>
        <div class="fxcon">
          {{tishiMessage}}
        </div>
      </div>
      <el-dialog title="选择下一待办人" :visible.sync="nextManager" width="30%" center>
           <div v-show="nextManager">
          <!-- <div  class="tableTitle">下一代理人</div> -->
           <el-radio-group v-model="nextUserId">
            <el-radio v-for="item in tableData" :key="item.id"  :label="item.id">
              <span class="user_name">{{item.name}}</span>
              <span class="user_part">{{item.department}}</span>
              </el-radio>
          </el-radio-group>
          
        </div>
          <span slot="footer" class="dialog-footer">
          <el-button type="primary" @click="addApply" size="small">确认</el-button>
          <el-button @click="nextManager = false" size="small">取 消</el-button>
      </span>
      </el-dialog>
      <div class="btn">
        <!-- <el-button type="primary" size="small" @click="close">暂存</el-button> -->
        <el-button type="primary"  size="small" v-show="this.$route.query.view != 'view'"  @click="submitPost">{{btntext}}</el-button>
        <el-button type="primary"  size="small" v-show="this.$route.query.currentRole != '交易员' && this.$route.query.view != 'view'"  @click="nopass">审核不通过</el-button>
        <el-button type="primary" size="small" @click="goback">取消</el-button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "accountDetail",
  data() {
    return {
      nextManager: false,
      tableData: [],
      nextUserId: '',
      step: 1,
      isAuthorization: 2,
      fileupload: this.$uploadfile,
      btntext: '审核通过',
      selectedData: [],
      isSheng: false,
      rules:{

      },
      fileList: [],
      recordShen: [], //审核记录
      tishiMessage:'',
      formList1: [
        {label: '机构编号', prop: 'no', value:''},{label: '机构名称', prop: 'bank', value:''},
        {label: '操作员工号', prop: 'jobNum', value:''},{label: '操作员姓名', prop: 'name', value:''},
      ],
      formData1: {},
       formList3: [
        {label: '产品代码', prop: 'code', value:'', btn: true},{label: '产品名称', prop: 'name', value:'', btn: false},
        {label: '产品类型', prop: 'type', value:''},{label: '利率类型', prop: 'rateType', value:''},
        {label: '发售方分类', prop: 'classification', value:''},{label: '发售银行性质', prop: 'issuingBank', value:''},
        {label: '期限结构', prop: 'termStructure', value:''},{label: '产品期限', prop: 'term', value:''},
        {label: '起息日', prop: 'interestDate', value:''},{label: '到期日', prop: 'dueDate', value:''},
        {label: '计息基础', prop: 'countBasis', value:''},{label: '预期收益率',start: 'expectedReturnStart', end: 'expectedReturnEnd', qujian: true, value:''},
        {label: '收益模式', prop: 'revenuePattern', value:''}
      ],
      formData3: {},
      formData:{},
      formList: [
        {label : '购买方式', value:'hhh', prop:'ways', select: true,
        options: [
            {label: '认购', value: '认购'},
            {label: '申购', value: '申购'}
           
        ]},
        {label : '金额（元）', value:'是', prop:'money',input: true},
        {label : '年化收益率', value:'是', prop:'annualized',input: true},
        {label : '机构标识', value:'hhh', prop:'identification', select: true,
         options: [
            {label: '系统外', value: '系统外'},
            {label: '系统内', value: '系统内'}
           
        ]},
        {label : '机构类型', value:'hhh', prop:'organizationType', select: true,
         options: [
           
        ]},
        {label : '机构名称', value:'是', prop:'organizationName',input: true}, 
        {label : '机构销售点', value:'是', prop:'institutionalPoint',input: true}, 
       
      ],
      boundId: '',
      multipleSelection: [],
      flowState:'', //流程是否结束
      nextRole: '',  //下一办理人角色名称
      isUpload: false,
      canUpload: true,
      fileUrl: [],
      filename: '',
      fileList2:[],
      aurl: this.$downfile
    };
  },
  methods: {
    // 文件
     
     handleRemove(file, fileList) {
      },
      handlePreview(file) {
      },
      handleExceed(files, fileList) {
        this.$message.warning(`当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
      },
      beforeRemove(file, fileList) {
        return this.$confirm(`确定移除 ${ file.name }？`);
      },
      //上传成功
      uploadSuccess(response, file, fileList) {

        file.info = this.filename
        this.fileList2 = fileList
        let item = {}
        item.info = this.filename
        item.name = file.name
        item.filename = response.data.fileName
        item.url = response.data.filePath
        this.fileUrl.push(item)
        this.filename = ''

    
      },
      delFile(index) {
          this.fileList2.splice(index, 1)
      },
    checkFile() {
      if(this.filename == '') {
        this.$message({
          type: 'warning',
          message: '请输入文件描述'
        })
        return false
      }
    },
    goback() {
      this.$router.go(-1)
    },
      //审核状态
      selectState(val) {
        if(val.state == 1 || val == '1') {
          return '已审批'
        }
        else{
          return '审批不通过'
        }
      },
    nopass() {
    
               this.$prompt('请输入驳回原因', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
          
              }).then( value => {
               
                // 审核不通过
                  if(this.step == 1 ){
                    this.nextUserId = null
                  }
                   
                    let data = {
                    flowId: parseInt(this.$route.query.flowId),
                    userId: this.formData.userId,
                    flowState: this.flowState,
                    nextUserId: this.nextUserId,
                    nextRole: this.nextRole,
                    state: 2,
                    content: value.value
                  }
                  this.axios.post('bondApplyFlow/approval', data).then(res => {
                    if(res.data.code ==200 ){
                      this.$message({
                        type: 'success',
                        message: '驳回成功'
                      })
                      this.$router.go(-1)
                    }
                  })
              }).catch(() => {
                this.$message({
                  type: 'info',
                  message: '取消输入'
                });       
              });
    },
    //复核员 获取是否有下一办理人
    getNextUser2() {
      let data = {
        roleName: this.$route.query.currentRole,
        flowId: this.$route.query.flowId
      }
      this.axios.get('financialProductsApply/getNextUser', {params: data}).then(res => {
        let response = res.data.data
      
        if(response.flowState == '1' || response.flowState == 1) {
            this.$message({
              type: 'warning',
              message: '提交下一办理人'
            })
            this.flowState = response.flowState
            this.nextRole  = response.nextRole
            this.nextManager = true
            this.tableData = response.nextUser
        }else {
     
             this.flowState = response.flowState
            if(response.nextRole != undefined || response.nextRole != null){
             
               this.nextRole  = response.nextRole
              this.nextUserId = response.nextUser[0].id
            }else {
              this.nextRole = null
              this.nextUserId = null
            }
           
           this.addApply()
        }
      })
    },
      
    
    submitPost() {
  
      if(this.isUpload && this.step == 0) {
        //上传成功后修改状态
              if(this.fileList2.length == 0) {
                    this.$message({
                    type: 'warning',
                    message: '请先上传文件'
                  })
                  return
              }
              let paraml = {
                fileUrl: JSON.stringify(this.fileUrl),
                applyId: parseInt(this.$route.query.applyId),
                // flowId: parseInt(this.$route.query.flowId)
              }
              
            this.axios.post('financialProductsApply/updateUploadState', paraml).then(res => {
                this.$message({
                  type: 'success',
                  message: '修改状态成功'
                })
                this.step = 1
                this.getNextUser2()
               // this.$router.go(-1)
            })
         }
      
      if(this.step == 1){
        //查看是否有下一办理人
          this.getNextUser2()
      }
    },
    addApply() {
       //获取下一办理人成功
         //提交给下一办理人

          let data = {
            flowId: parseInt(this.$route.query.flowId),
            
            flowState: this.flowState,
            nextUserId: this.nextUserId,
            nextRole: this.nextRole,
            state: 1,
            content: '通过',
            userId: this.formData.userId
          }


          this.axios.post('bondApplyFlow/approval', data).then(res => {
            if(res.data.code ==200 ){
              this.$message({
                type: 'success',
                message: '提交成功'
              })
              this.$router.go(-1)
            }
          })
    },
  
    
    getOppoAccountInfo() {
      //交易对手账户信息
      let param = {
        accountId: sessionStorage.getItem('counterpartyAccountId')
      }
      this.axios.get('counterparty/selectOneAccount', {params: param}).then((res) => {
        this.formData2 = res.data.data
      })
    },
    close() {
      this.$router.go(-1);
    },

    getBondFlowDetail() {
      let data = {
        applyId: this.$route.query.applyId,
        model: '理财产品交易'
      }
      this.axios.get('bondApplyFlow/selectOne', {params: data}).then(res => {
          let response = res.data.data
          this.formData = response.productApply
          this.formData3 = response.product
          this.formData1 = response.user
          this.recordShen = response.list
          if(this.formData.warn != null) {
            this.tishiMessage = this.formData.warn
          }
          if(response.files != '') {
            this.fileList = response.files
          }
          this.selectedData = response.redeemDetail
          if(response.authorizationFiles != '') {
            this.fileList2 = response.authorizationFiles
            this.fileUrl = response.authorizationFiles
            this.canUpload = false
            this.isUpload = true
            if(this.$route.query.currentRole == '交易员') {
              this.canUpload = true
            }
          }
      })
    }
  },
  mounted() {
    if(this.$route.query.flowState == '3') {
      //被驳回
      this.btntext = '提交'
    }else {
          //省联社 提交文件
      if(this.$route.query.flowState == '1' && this.$route.query.currentRole == '交易员') {
        this.isUpload = true
        this.step = 0
        this.btntext = '提交'
      }
      
    }
  this.getBondFlowDetail()
    
  },

};
</script>

<style lang="scss">
.el-message{

    z-index: 2100!important
  }
#licaiDetail {
 .el-input__inner{
   color:white;
   border:0;
   background: transparent
 }

  #fujian2, #shengl{
  td{
    border:1px solid white;
    padding: 8px;
     .el-upload-list{
      display: none;
    }
    .upload-demo{
      display: inline;
    }
    .el-input__inner{
      background: transparent;
      color:white;
      border: 0
    }
  }
}
  .upload-demo{
    display: flex;
    .el-upload{
      width:30%
    }
    .el-upload-list{
      width: 70%;
      .el-upload-list__item-name{
        color: white;
      }
    }
  }

  .tableBox {
    padding-top: 10;
    color: white;
    .formlist{
      .el-form-item{
        width:49%;
        margin:0;
        border: 1px solid white;
        .el-form-item__label, .el-form-item__content{
            padding: 6px 2px;
            border-right: 1px solid white;
        }
        .el-form-item__label{
          text-align: center;
            width:45%;
            background: rgba(53,58,58,0.8);
            color:white;
            box-sizing: border-box;
        }
        .el-form-item__content{
          width:55%;
          text-align: center;
          background: rgba(53,58,58,0.55);
          box-sizing: border-box;
        }
      }
    }
    .el-table__empty-text{
      color:white;
    }
    .tableTitle {
      line-height: 36px;
      padding-left: 20px;
      margin: 12px 0;
    }
    table {
      
      border: 1px solid white;
      width: 100%;
      text-align: center;
      border-collapse: collapse;
       .el-table tr{
          background: transparent;
      }
      // margin-bottom: 20px;
      tr {
        td {
          
          &:nth-child(odd) {
            background: rgba(53, 58, 58, 0.55);
          }
          &:nth-child(even) {
            background: rgba(53, 58, 58, 0.55);
          }
        }
      }
    }
    .riskTip {
      .fxtq {
        margin-bottom: 20px;
      }
      .fxcon {
        border: 1px solid white;
        background-color: #4d534e;
        padding: 20px;
        margin-bottom: 20px;
      }
    }
    .btn {
      text-align: center;
      margin-top:20px;
    }
  }
  .DiaFxcon {
    background-color: white;
    padding: 20px 10px;
    margin-bottom: 20px;
  }
      .el-radio-group{
    width:100%;
    height: 320px;
    overflow-y: scroll;
    .el-radio{
      margin-bottom: 15px;
      width: 100%;
      display: block;
       .el-radio__label {
        width: 80%;
        display: inline-block;
          
        .user_name, .user_part {
              padding: 15px;
              width: 48%;
              display: inline-block;
              text-align: center;
              border: 1px solid #efefef
            }
      }  
     
    }
     .el-radio+.el-radio{
        margin-left: 0
      }
  }
}
</style>
